package task01;

import java.util.Scanner;

public class GuessGame {
    public static void start(){
        /*1、产生随机数
        * 2、循环：（猜中为止）
        *    接受输入
        *    判断：提示大于，小于
        *          猜中，提示并退出*/
    //Math.random()得到的是大于等于0且小于1的double
        int random=(int) (Math.random()*100);

        /*int guess=-1;

        while (guess!=random) {
            System.out.println("请输入猜测的数字(0-100):");
            Scanner scanner=new Scanner(System.in);
            guess=scanner.nextInt();

            if (guess>random){
                System.out.println("大了");
            }else if(guess<random){
                System.out.println("小了");
            }else{
                System.out.println("猜中了");
                break;
            }
        }*/
        while (true) {
            System.out.println("请输入猜测的数字(0-100):");
            Scanner scanner=new Scanner(System.in);
            int guess=scanner.nextInt();

            if (guess>random){
                System.out.println("大了");
            }else if(guess<random){
                System.out.println("小了");
            }else{
                System.out.println("猜中了");
                break;
            }
        }
    }
}
